package com.example.leetdemo.finash;

import java.util.HashMap;
import java.util.Map;

public class Solution205 {

    public boolean isIsomorphic(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }
        Map<Character, Character> smap = new HashMap<>();
        Map<Character, Character> tmap = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            if (!smap.containsKey(s.charAt(i))) {
                smap.put(s.charAt(i), t.charAt(i));
            }
            if (!tmap.containsKey(t.charAt(i))) {
                tmap.put(t.charAt(i), s.charAt(i));
            }
            if (!smap.get(s.charAt(i)).equals(t.charAt(i)) || !tmap.get(t.charAt(i)).equals(s.charAt(i))) {
                return false;
            }
        }

        return true;
    }

    public static boolean isHappy(int n) {
        Map<Integer, Boolean> map = new HashMap<>();
        while(!map.containsKey(n)) {
            map.put(n, false);
            int temp = 0;
            while(n > 0) {
                temp += (n % 10) * (n % 10);
                n = n / 10;
            }
            n = temp;
            if(temp == 1) {
                return true;
            }

        }
        return false;
    }

    public static void main(String[] args) {
        System.err.println(isHappy(19));
    }

}
